home *** CD-ROM | disk | FTP | other *** search
/ Megahits 3 / Megahits 3 (1994)(GTI - Rhein-Main-Soft)(DE)[!].iso / module / utilities / archives / k1ed_v5_31.lha / src / controllers.c next >
C/C++ Source or Header  |  1992-10-25  |  8KB  |  321 lines

  1. #include "inc.h"
  2. #include "defs.H"
  3.  
  4. #define SETVOL         scroll[0].Prop.Info.HorizPot = vol*65535/127;
  5. #define SETMOD         scroll[1].Prop.Info.HorizPot = mod*65535/127;
  6. #define SETPITCH    scroll[2].Prop.Info.HorizPot = pitch*65535/255;
  7.  
  8. void Controllers(void);
  9. void TransmitVolume(int);
  10. void TransmitModulation(int);
  11. void TransmitPitch(int);
  12.  
  13. void Controllers(void)
  14. {
  15.     struct NewWindow nw;
  16.     struct Window     *WIN;
  17.     struct RastPort *RP;
  18.     int             i,id;
  19.     static struct ScrollBlock scroll[3];
  20.     static struct GadgetBlock buf[4];
  21.     struct Gadget *gad;
  22.     long vol,mod,pitch;
  23.     char str[20];
  24.  
  25.     nw.LeftEdge = 20;
  26.     nw.TopEdge = 20;
  27.     nw.Width = 400;
  28.     nw.Height = 80;
  29.     nw.DetailPen = 0;
  30.     nw.BlockPen = 1;
  31.     nw.Title ="K1-II - MIDI Controllers";
  32.     nw.Flags = RMBTRAP|ACTIVATE|WINDOWCLOSE|REPORTMOUSE|SMART_REFRESH|WINDOWDRAG|(SCREEN == 0 ? WINDOWDEPTH : NULL) ;
  33.     nw.IDCMPFlags = CLOSEWINDOW|MOUSEBUTTONS|GADGETUP|GADGETDOWN;
  34.     nw.Type = (SCREEN != 0 ? CUSTOMSCREEN : WBENCHSCREEN);
  35.     nw.CheckMark = NULL;
  36.     nw.NextGadget=NULL;
  37.     nw.Screen = (SCREEN != 0 ? scr : NULL);
  38.     nw.BitMap = NULL;
  39.     nw.MinWidth = 0;
  40.     nw.MinHeight = 0;
  41.     nw.MaxWidth = 0;
  42.     nw.MaxHeight = 0;
  43.  
  44.     for (i=0;i<=2;i++)    
  45.     {
  46.         MakeScrollBar(&scroll[i],HORIZSLIDER,250,100,15+15*i);
  47.         scroll[i].ArrowUpLt.GadgetID = 3*i;
  48.         scroll[i].ArrowDnRt.GadgetID = 3*i+1;
  49.         scroll[i].Prop.Gadget.GadgetID = 3*i+2;
  50.     }
  51.  
  52.     scroll[0].Prop.Info.HorizBody =65535/127; 
  53.     scroll[1].Prop.Info.HorizBody =65535/127; 
  54.     scroll[2].Prop.Info.HorizBody =65535/255; 
  55.  
  56.     vol=64;
  57.     mod=0;
  58.     pitch=127;
  59.  
  60.     SETVOL
  61.     SETMOD
  62.     SETPITCH    
  63.  
  64.     nw.FirstGadget=&scroll[0].ArrowUpLt;
  65.     scroll[0].Prop.Gadget.NextGadget=&scroll[1].ArrowUpLt;
  66.     scroll[1].Prop.Gadget.NextGadget=&scroll[2].ArrowUpLt;
  67.     scroll[2].Prop.Gadget.NextGadget=NULL;
  68.  
  69.     MakeGadget(&buf[0],"Reset",30,65);
  70.     buf[0].Gadget.NextGadget=nw.FirstGadget;
  71.     buf[0].Gadget.GadgetID=20;
  72.     nw.FirstGadget=&buf[0].Gadget;
  73.  
  74.     MakeGadget(&buf[1],"All notes off",90,65);
  75.     buf[1].Gadget.NextGadget=nw.FirstGadget;
  76.     buf[1].Gadget.GadgetID=21;
  77.     nw.FirstGadget=&buf[1].Gadget;
  78.  
  79.     MakeGadget(&buf[2],"Omni on",210,65);
  80.     buf[2].Gadget.NextGadget=nw.FirstGadget;
  81.     buf[2].Gadget.GadgetID=22;
  82.     nw.FirstGadget=&buf[2].Gadget;
  83.  
  84.     MakeGadget(&buf[3],"Omni off",280,65);
  85.     buf[3].Gadget.NextGadget=nw.FirstGadget;
  86.     buf[3].Gadget.GadgetID=23;
  87.     nw.FirstGadget=&buf[3].Gadget;
  88.  
  89.     Center(&nw,0,0);
  90.     WIN=(struct Window *) OpenWindow(&nw);
  91.     if (WIN==NULL) Error("Can't open controller window");
  92.     RP=WIN->RPort;
  93.     SetFont(RP,textfont);
  94.  
  95.     Print(WIN,10,22,"Volume");
  96.     Print(WIN,10,37,"Modulation");
  97.     Print(WIN,10,52,"Pitchbend");
  98.  
  99.     for (i=0;i<=2;i++) RefreshGList(&scroll[i].Prop.Gadget,WIN,NULL,1);
  100.     
  101. Loop: ;
  102.     sprintf(str,"%4ld",vol);
  103.     Print(WIN,350,22,str);
  104.     sprintf(str,"%4ld",mod);
  105.     Print(WIN,350,37,str);
  106.     sprintf(str,"%4ld",pitch-127);
  107.     Print(WIN,350,52,str);
  108.  
  109.     WaitPort(WIN->UserPort);
  110.     while(mesg = (struct IntuiMessage *) GetMsg(WIN->UserPort))
  111.     {
  112.         class=mesg->Class; 
  113.         code=mesg->Code;
  114.         if (class == GADGETUP || class == GADGETDOWN)
  115.         {
  116.             gad=mesg->IAddress;
  117.             id=gad->GadgetID;
  118.         }
  119.         ReplyMsg((struct Message *)mesg);
  120.     
  121.         switch(class)
  122.         {
  123.             case CLOSEWINDOW:
  124.             {   
  125.                 while(mesg = (struct IntuiMessage *) GetMsg(WIN->UserPort)) ReplyMsg((struct Message *)mesg);
  126.                 CloseWindow(WIN);
  127.                 return;
  128.                 break;
  129.             }
  130.         
  131.             case MOUSEBUTTONS:
  132.             {
  133.                 if (code==MENUDOWN)
  134.                 {
  135.                     while(mesg = (struct IntuiMessage *) GetMsg(WIN->UserPort)) ReplyMsg((struct Message *)mesg);
  136.                     CloseWindow(WIN);
  137.                     return;
  138.                 }    
  139.                 break;
  140.             }
  141.     
  142.             case GADGETUP:
  143.             {
  144.                 int nr,pos;
  145.     
  146.                 nr=id / 3;
  147.                 pos=id % 3;
  148.         
  149.                 if (id==20)                            /* Reset */
  150.                 {
  151.                     vol=64;
  152.                     mod=0;
  153.                     pitch=127;
  154.     
  155.                     TransmitVolume(vol);
  156.                     TransmitModulation(mod);
  157.                     TransmitPitch(pitch);
  158.     
  159.                     SETVOL
  160.                     SETMOD
  161.                     SETPITCH    
  162.     
  163.                     for (i=0;i<=2;i++) RefreshGList(&scroll[i].Prop.Gadget,WIN,NULL,1);
  164.                 }
  165.     
  166.                 if (id==21)                        /* All notes off */
  167.                 {
  168.                     unsigned char buf[3];
  169.                     int i;
  170.     
  171.                     buf[0]=128+MASTERCHANNEL;
  172.                     buf[2]=0;
  173.                     for (i=0;i<=127;i++)
  174.                     {
  175.                         buf[1]=i;
  176.                         PutMidiMsg(source,buf);
  177.                         Delay(1);
  178.                     }
  179.                 }    
  180.                 
  181.                 if (id==22)                        /* Omni on */
  182.                 {
  183.                     unsigned char buf[3];
  184.     
  185.                     buf[0]=176; buf[1]=125; buf[2]=0;
  186.                     PutMidiMsg(source,buf);
  187.                     Delay(1);
  188.                 }    
  189.                 
  190.                 if (id==23)                        /* Omni off */
  191.                 {
  192.                     unsigned char buf[3];
  193.     
  194.                     buf[0]=176; buf[1]=124; buf[2]=0;
  195.                     PutMidiMsg(source,buf);
  196.                     Delay(1);
  197.                 }    
  198.             
  199.                 if (pos<=1)
  200.                 {
  201.                     vol  =127*scroll[0].Prop.Info.HorizPot/65535;
  202.                     mod  =127*scroll[1].Prop.Info.HorizPot/65535;
  203.                     pitch=255*scroll[2].Prop.Info.HorizPot/65535;
  204.                 
  205.                 }    
  206.     
  207.                 if (pos==2)
  208.                 {
  209.                     if (nr==0)    vol=127*scroll[0].Prop.Info.HorizPot/65535;
  210.                     if (nr==1)    mod=127*scroll[1].Prop.Info.HorizPot/65535;
  211.                     if (nr==2)    pitch=255*scroll[2].Prop.Info.HorizPot/65535;
  212.     
  213.                     sprintf(str,"%4ld",vol);
  214.                     Print(WIN,350,22,str);
  215.                     sprintf(str,"%4ld",mod);    
  216.                     Print(WIN,350,37,str);
  217.                     sprintf(str,"%4ld",pitch-127);    
  218.                     Print(WIN,350,52,str);
  219.     
  220.                     if (nr==0) TransmitVolume(vol);
  221.                     if (nr==1) TransmitModulation(mod);
  222.                     if (nr==2) TransmitPitch(pitch);    
  223.                 }
  224.                 break;
  225.             }
  226.     
  227.             case GADGETDOWN:
  228.             {
  229.                 int nr,pos;
  230.     
  231.                 nr=id / 3;
  232.                 pos=id % 3;
  233.                 
  234.                 if (pos==2 && id<10)
  235.                 {
  236.                     while (scroll[0].Prop.Gadget.Flags & SELECTED || scroll[1].Prop.Gadget.Flags & SELECTED || scroll[2].Prop.Gadget.Flags & SELECTED )
  237.                     {
  238.                         if (nr==0)    vol  =127*scroll[0].Prop.Info.HorizPot/65535;
  239.                         if (nr==1)    mod  =127*scroll[1].Prop.Info.HorizPot/65535;
  240.                         if (nr==2)    pitch=255*scroll[2].Prop.Info.HorizPot/65535;
  241.     
  242.                         sprintf(str,"%4ld",vol);
  243.                         Print(WIN,350,22,str);
  244.                         sprintf(str,"%4ld",mod);    
  245.                         Print(WIN,350,37,str);
  246.                         sprintf(str,"%4ld",pitch-127);    
  247.                         Print(WIN,350,52,str);
  248.     
  249.                         if (nr==0) TransmitVolume(vol);
  250.                         if (nr==1) TransmitModulation(mod);
  251.                         if (nr==2) TransmitPitch(pitch);    
  252.                     }
  253.                         vol=127*scroll[0].Prop.Info.HorizPot/65535;
  254.                         mod=127*scroll[1].Prop.Info.HorizPot/65535;
  255.                         pitch=255*scroll[2].Prop.Info.HorizPot/65535;
  256.     
  257.                         sprintf(str,"%4ld",vol);
  258.                         Print(WIN,350,22,str);
  259.                         sprintf(str,"%4ld",mod);    
  260.                         Print(WIN,350,37,str);
  261.                         sprintf(str,"%4ld",pitch-127);    
  262.                         Print(WIN,350,52,str);
  263.     
  264.                         if (nr==0) TransmitVolume(vol);
  265.                         if (nr==1) TransmitModulation(mod);
  266.                         if (nr==2) TransmitPitch(pitch);    
  267.                 }
  268.                 break;
  269.             }    
  270.     
  271.             default: goto Loop;
  272.         }        
  273.     }
  274. goto Loop;
  275. }
  276.  
  277. /**********************************************************************************/
  278. /***                                                                            ***/
  279. /**********************************************************************************/
  280.  
  281. void TransmitVolume(int val)
  282. {
  283.     unsigned char buf[3];
  284.  
  285.     buf[0]=176; 
  286.     buf[1]=7;
  287.     buf[2]=val;
  288.  
  289.     PutMidiMsg(source,buf);
  290. }
  291.  
  292. /**********************************************************************************/
  293. /***                                                                            ***/
  294. /**********************************************************************************/
  295.  
  296. void TransmitModulation(int val)
  297. {
  298.     unsigned char buf[3];
  299.  
  300.     buf[0]=176; 
  301.     buf[1]=1;
  302.     buf[2]=val;
  303.  
  304.     PutMidiMsg(source,buf);
  305. }
  306.  
  307. /**********************************************************************************/
  308. /***                                                                            ***/
  309. /**********************************************************************************/
  310.  
  311. void TransmitPitch(int val)
  312. {
  313.     unsigned char buf[3];
  314.  
  315.     buf[0]=224; 
  316.     buf[1]=0;
  317.     buf[2]=val/2;
  318.  
  319.     PutMidiMsg(source,buf);
  320. }
  321.